package com.glsc.ngateway.platform.repo;

import com.glsc.ngateway.platform.domain.Vpn;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;


@Repository
public interface GlscVpnRepository extends JpaRepository<Vpn, Long>, JpaSpecificationExecutor<Vpn> {
    @Query(value = "select * from GlscVpn p where 1=1 " +
            "and (:#{#paramSearchDto.name}  is null OR p.name  LIKE CONCAT('%', :#{#paramSearchDto.name},  '%')) " +
            "and (:#{#paramSearchDto.account}  is null OR p.account  LIKE CONCAT('%', :#{#paramSearchDto.account},  '%')) " +
            "and (:#{#paramSearchDto.describe}  is null OR p.describe  LIKE CONCAT('%', :#{#paramSearchDto.describe},  '%')) " +
            "and (:#{#paramSearchDto.status}  is null OR p.status  = :#{#paramSearchDto.status})  " +
            "and (:#{#paramSearchDto.pathId}  is null OR p.path_id  = :#{#paramSearchDto.pathId})  " +
            "and (:#{#paramSearchDto.pathName}  is null OR p.path_name  LIKE CONCAT('%', :#{#paramSearchDto.pathName},  '%')) " +
            "and (:#{#paramSearchDto.resourceId}  is null OR p.resource_id  = :#{#paramSearchDto.resourceId})  " +
            "and (:#{#paramSearchDto.resourceName}  is null OR p.resource_name  LIKE CONCAT('%', :#{#paramSearchDto.resourceName},  '%')) "
            ,nativeQuery = true)
    Page<Vpn> searchByParam(Pageable pageable, Vpn paramSearchDto);

}
